package com.lingnan.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.kevinsawicki.http.HttpRequest;
import com.lingnan.service.WeChatService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author 梁兴达
 * @Date 2022/4/16 20:09:36
 * @Version 1.0
 */
@Service
public class WeChatServiceImpl implements WeChatService {
    @Override
    public JSONObject codetoopenid(String code) {
        Map<String, String> data = new HashMap<>();
        data.put("appid", "wx26cb0f6831323ab9");
        data.put("secret", "b3c066aea4de11f949b624c1f5659c35");
        data.put("js_code", code);
        data.put("grant_type", "authorization_code");


        String response = HttpRequest.get("https://api.weixin.qq.com/sns/jscode2session").form(data).body();
        System.out.println("Response was: " + response);
        JSONObject obj= JSON.parseObject(response);//将json字符串转换为json对
        //System.out.println(obj);
        return obj;
    }
}
